(function(window){
	var Index_detail = {
		data:{},
		init: function(data){
			Index_detail.data=data;
			$("[data-page='Index_detail']").find("#header").hide();
			//alert(123);
			//console.log(data);
			hiApp.showIndicator();
			Index_detail.bindEvent();
			//设置选中菜单
			var cur_tabbar_active=$("[data-page='Index_detail']").find("[name='cur_tabbar_active']").val();
			hiApp.active_toolbar(cur_tabbar_active);
			var video_width=$(window).width();
			var video_h=video_width*0.5625;
			$("[data-page='Index_detail']").find(".videoPlayer_div").width(video_width);
			$("[data-page='Index_detail']").find(".videoPlayer_div").height(video_h);
			
			/*********播放器*****/
			var play_url="";
			var type= "_600x360.mp4";
			if($(window).width()>500){
				type= "_848x476.mp4";
			}
			
			/*if(networkType!="wifi" && networkType!="undefind"){
				dialog("您当前使用的是"+networkType+"网络，只能听声音哦");
				type=".mp3";
			}*/	
			play_url=mp4_url+"/"+part_id+type;
			var param={
					id:'videoPlayer',
					url:play_url,
					image:mp4_url+"/"+part_id+".jpg",
					loaded:"loadedHandler('videoPlayer')",//【初始化调到第几秒
				};	
				 
			 if(app_params.view_type=="app"){
					//var fs = api.require('fs');
					var down_id="down_"+words_id+"_"+part_id;
					//var file="fs://movie/"+data.query.id+"_"+part_id+".mp4";
					file_data=has_down_file(down_id);
					if(file_data){
						param.url=file_data.savePath;
						$("#"+down_id).html("本地播放");
					}
					open_video(param);
			 }else{
					open_video(param);
			 }
			
			/*****页面初始化***/
			load_read_words(my_read_words);
			Index_detail.set_words_active();
			/********字幕分页***/
			if($(window).width()>400){
				var words_content_h=$(window).height()-video_h-52-70;
				words_param['limit']=Math.floor(words_content_h/41); 
			}else if($(window).width()>350){
				var words_content_h=$(window).height()-video_h-52-70;
				words_param['limit']=Math.floor(words_content_h/50); 
			}
			/******字幕***/
			words_pages={};
			subtitle_list['ckplayer_videoPlayer']={};
			//var englishs= $("[data-page='Index_detail'] .page_1").find(".english");
			$.each(words_json,function(i,v){
				var one={
						'start_time_int':v.start_time_int,
						'end_time_int':v.end_time_int,
						'words':v.english,
					}
				subtitle_list['ckplayer_videoPlayer'][i]=one;
				var page=Math.ceil((i+1)/words_param['limit']);
				if(!words_pages[page]){
					words_pages[page]=new Array();
				}
				words_pages[page].push(v);
			})
			
			/******字幕切换*****/
			box_render(words_pages,"#WordsTemplate","#words_content_wrapper","html");
			$("[data-page='Index_detail']").find(".words_content .list-group").height(words_content_h);
			//alert($(".swiper-slide").length);
			init("Index_detail");
			Index_detail.int_swiper();
			hiApp.hideIndicator();
			
        },
		set_words_active:function(){
			//看到
				var data=Index_detail.data;
				if(data.query){
					set_part_id_select(data.query.part_id);
				}
		},
		int_swiper:function(){//实例化字幕列表
			 setTimeout(function(){
				  swiper = new Swiper('.swiper-container', {
					pagination: '.swiper-pagination',
					nextButton: '#swiper-button-next',
					prevButton: '#swiper-button-prev',
					autoHeight: true, //enable auto height
					allow_touch_swiper:false,
					after_slideTo:function(){
						Index_detail.after_slideTo(swiper)
					}
				}); 
				
				var key="words_"+words_id+"_"+part_id;
				var history_read=hiApp.S(key);
				if(history_read){
					to_page=Math.floor(history_read.line/words_param['limit']);
					swiper_time=2;
					swiper.slideTo(to_page);
				}
			},1);
		},
		swiper_Seek:function(){//根据字幕调整视频时间，手动调整字幕的时候
			//console.log("swiper_Seek:"+swiper_time);
			if(swiper_time==1)return ;
			var s=$("#words_content_wrapper .swiper-slide-active .english:first").attr("start_time_int");
			var e=$("#words_content_wrapper .swiper-slide-active .english:last").attr("end_time_int");
			CKobject.getObjectById("ckplayer_videoPlayer").videoSeek(s);
			swiper_time=2;
			l=(e-s-1)*1000;
			clearTimeout(id_of_settimeout);
			id_of_settimeout=setTimeout(function(){
				swiper_time=1;	
			},l)
		},
		after_slideTo:function(swiper){//一下页
			//console.log(swiper.activeIndex);
			if(swiper){
				var key="words_"+words_id+"_"+part_id;
				var activeIndex=swiper.activeIndex;
				var array={
						all_line:$("#words_content_wrapper .english").length,
						line:activeIndex*words_param['limit'],
					};
				
				hiApp.S(key,array);
				load_read_words(my_read_words);
				Index_detail.set_words_active();
				clearTimeout(id_of_settimeout);
				id_of_settimeout=setTimeout(function(){
					Index_detail.swiper_Seek();
				},200);
			}
			 
		},
		afterShow:function(){
			 
		},
		set_swiper_Seek:function(){
			console.log('set_swiper_Seek');
			swiper_time=2;
		},
		bindEvent: function(){
            var bindings = [
			{
                element: '#swiper-button-next',
                event: hiApp.device.click,
                handler: Index_detail.set_swiper_Seek
            },
			{
                element: '#swiper-button-prev',
                event: hiApp.device.click,
                handler: Index_detail.set_swiper_Seek
            }
			
			];
			 bindEvents(bindings);
        },
		
    };
		
	window.BoxEng_Index_detailCtrl = Index_detail;
						
})(window);